<template>
  <el-dialog class="combination-open" :visible.sync="visible" :title="dataForm.groupId?'编辑':'添加'" :close-on-click-modal="false">
    <el-form ref="dataForm" :rules="rules" :model="dataForm" label-position="right" label-width="80px" style="width: 500px; margin-left:50px;">
        <el-form-item label="对标指数" prop="groupIndex">
          <indexSelectTree :multiple="false" :width="420" :indexType.sync="dataForm.groupIndex"></indexSelectTree>
        </el-form-item>
        <el-form-item label="分组名称" prop="groupName">
          <el-input v-model="dataForm.groupName" />
        </el-form-item>
        <el-form-item label="备注" prop="mark">
          <el-input type="textarea" :rows="3" placeholder="最多120个字符" v-model="dataForm.mark" maxlength="120" size="mini" show-word-limit style="width: 500px;"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="visible = false">取消</el-button>
        <el-button type="primary" @click="addSubmit">提交</el-button>
      </div>
  </el-dialog>
</template>

<script>
import indexSelectTree from '@/components/investComn/indexSelectTree.vue'
import { addOrUpdateOrDeleteInvestGroup } from '@/api/afterInvest'

export default {
  components: { indexSelectTree },
  props: {
    userId: String | Number
  },
  data() {
    return {
      visible: false,
      dataForm: {
        groupId: '',
        groupName: '',
        mark: ''
      },
      rules: {
        groupName: [{ required: true, message: '分组名称必填', trigger: 'change' }]
      }
    }
  },
  methods: {
    init(row) {
      this.visible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        this.dataForm = {
          groupId: '',
          groupName: '',
          mark: ''
        }
        if(row) {
          this.dataForm = Object.assign({}, row)
        }
      })
    },
    addSubmit() {
      addOrUpdateOrDeleteInvestGroup({
        ...this.dataForm,
        createdBy: this.userId
      }).then(res => {
        if(res.code == 0) {
          this.$notify({
            message: res.body,
            type: 'success',
            duration: 2000
          })
          this.visible = false
          this.$emit('closeOpen')
        }
      })
    },
  }
}
</script>

<style lang="scss" scoped>
.combination-open {
  ::v-deep .el-dialog { min-width: 800px; }
}
</style>


